﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data;

namespace Poligono.Data
{
    /// <summary>
    /// Only for Static menbers, class with Dispose can't be static
    /// </summary>
    public partial class DbUtil
    {
        /// <summary>
        /// Create the DbCommand with commun param
        /// </summary>
        /// <param name="dataAcessProvider"></param>
        /// <param name="commandText"></param>
        /// <param name="commandType"></param>
        /// <param name="commandTimeOut"></param>
        /// <returns></returns>
        public static DbCommand NewDbCommand(DataAcessProvider dataAcessProvider, string commandText, CommandType commandType, int commandTimeOut)
        {
            if(dataAcessProvider != null)
            {
                DbCommand dbCommand = dataAcessProvider.ProviderFactory.CreateCommand();
                dbCommand.CommandText = commandText;
                dbCommand.CommandType = commandType;
                dbCommand.CommandTimeout = commandTimeOut;
                dbCommand.Connection = dataAcessProvider.Connection;
                if (dbCommand.Transaction == null)
                    dbCommand.Transaction = dataAcessProvider.Transaction;
                return dbCommand;
            }
            throw new NullReferenceException("Data Acess Provider is null");
        }
    }
}
